package com.open4cn.simulator.connect.tcp;

import com.open4cn.simulator.connect.tcp.handler.DispatcherHandler;
import com.open4cn.simulator.connect.tcp.handler.ReadBlockHandler;
import com.open4cn.simulator.connect.tcp.handler.ReadLogHandler;
import com.open4cn.simulator.connect.tcp.handler.WriteLogHandler;
import com.open4cn.simulator.connect.tcp.listenner.ConnectStatusFutureListener;
import com.open4cn.simulator.core.device.DeviceStatus;
import com.open4cn.simulator.core.parser.InstructionParserChain;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description 不能作为完整的IConnector对象使用
 * @Email yinxiaopeng@zj.tech
 * @date 2022-08-07 18:41
 */
public class TCPClientQuickConnector extends TCPClientConnector {

    public TCPClientQuickConnector(DeviceStatus deviceStatus, InstructionParserChain chain) {
        super();
        init(deviceStatus, chain);
    }


    private void init(DeviceStatus deviceStatus, InstructionParserChain chain) {
        beforeDecod(new ReadLogHandler(deviceStatus.getDeviceName()));
        beforeDecod(new ReadBlockHandler(deviceStatus));
        afterDecod(new DispatcherHandler(chain));
        afterEncod(new WriteLogHandler(deviceStatus.getDeviceName()));
        addFutureListenner(new ConnectStatusFutureListener(this.getConnectStatus()));
    }
}
